# encoding:utf-8

import requests
import base64

def myocr(img):

    '''
    通用文字识别（高精度版）
    '''

    request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic"
    # 二进制方式打开图片文件
    # f = open('static/images/tangs.jpg', 'rb')
    # img = base64.b64encode(f.read())

    params = {"image":img}
    access_token = '24.22de20d40849855c8d4f32894fb90404.2592000.1603596188.282335-16510676'
    request_url = request_url + "?access_token=" + access_token
    headers = {'content-type': 'application/x-www-form-urlencoded'}
    response = requests.post(request_url, data=params, headers=headers)
    result=None
    if response:
        result=response.json()

    return result


